import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';
import 'package:xin_nuo_pda/base/BaseController.dart';
import 'package:xin_nuo_pda/http/api/lot_api.dart';

import 'DataUploadState.dart';

class DataUploadController extends BaseController {
  final DataUploadState state = DataUploadState();

  getLotInfo(String lot) async{
    Map<String, dynamic> params = {'LOTID': lot};
    var result = await LotApi.lotInfo(canelToken, params: params);
    if (result.ok) {
      state.lotEntity = result.data;
      var edcData = await LotApi.getEdcDate(canelToken, params: params);
      if(edcData.ok){
          state.edcDataEntity = edcData.data;
          if(state.edcDataEntity!.eDCSETLIST!.isNotEmpty){
            state.edcDataEntity!.eDCSETLIST![0].eDCSETBINLINELIST?[0].VALUE = state.lotEntity?.mAINQTY.toString();
            state.edcDataEntity!.eDCSETLIST![0].eDCSETBINLINELIST?[0].check = '100%';
            state.edcData = state.edcDataEntity!.eDCSETLIST![0].eDCSETBINLINELIST;
          }else{
            Get.snackbar('提示', '服务器返回EDC数据为空！');
          }
          update([state.upload]);
      }
    }
  }

  report() async{
    state.edcDataEntity!.eDCSETLIST![0].eDCSETBINLINELIST = state.edcData ;
    Map<String, dynamic> params = {'LOTID': state.lotEntity!.lOTID,'EDCSETLIST':state.edcDataEntity!.eDCSETLIST};
    var result = await LotApi.report(canelToken, params: params);
    if(result.ok){
      Fluttertoast.showToast(
        msg: "上报成功",
        toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.CENTER,
        timeInSecForIosWeb: 1,
      );
        Get.back();
    }
  }
}
